var t = getApp();

Page({
    data: {
        keyword: "",
        list: [],
        result: [],
        checked: !1
    },
    onLoad: function(t) {},
    initData: function() {
        this.data.list = [], this.data.result = [], this.data.checked = !1, this.data.keyword = "";
    },
    getData: function() {
        var a = this, e = t.getNetAddresss("plugin.warehouse.frontend.controllers.takeDelivery.list");
        t._postNetWork({
            url: e,
            data: {
                keyword: this.data.keyword
            },
            success: function(t) {
                var e = t.data;
                if (1 == e.result) {
                    for (var i = e.data, o = 0; o < i.length; o++) i[o].total = 1;
                    a.setData({
                        list: i
                    });
                } else wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    toOrder: function() {
        if (0 != this.data.result.length) {
            for (var t = [], a = 0; a < this.data.result.length; a++) {
                var e = {};
                e.goods_id = this.data.list[Number(this.data.result[a])].id, e.total = this.data.list[Number(this.data.result[a])].total, 
                e.option_id = 0, t.push(e);
            }
            var i = {
                tag: "warehouse"
            };
            i.goods = JSON.stringify(t);
            wx.navigateTo({
                url: "/packageD/buy/myOrder_v2/myOrder_v2?tag=warehouse&goodCollection=" + i.goods
            });
        } else wx.showToast({
            icon: "none",
            title: "请选择礼物！",
            duration: 1e3
        });
    },
    onChangeSearch: function(t) {
        this.setData({
            keyword: t.detail
        });
    },
    onSearch: function() {
        this.setData({
            list: []
        }), this.getData();
    },
    checkChange: function(t) {
        if (0 != this.data.list.length) {
            this.setData({
                checked: t.detail
            });
            var a = [];
            t.detail && this.data.list.forEach(function(t, e) {
                a.push(e.toString());
            }), this.setData({
                result: a
            });
        }
    },
    changeGroup: function(t) {
        this.setData({
            result: t.detail,
            checked: t.detail.length == this.data.list.length
        });
    },
    onChangeStepper: function(t) {
        this.data.list[t.currentTarget.dataset.index].total = t.detail;
    },
    onReady: function() {},
    onShow: function() {
        this.initData(), this.getData();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});